import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/components/Login'
import Register from '@/components/Register'
import Index from '@/components/Index'
import ExistChannel from '@/components/channel_manage/ExistChannel'
import CreateChannel from '@/components/channel_manage/CreateChannel'

import CompletedWork from '@/components/artical_manage/CompletedWork'
import CreateWork from '@/components/artical_manage/CreateWork'
import ExaminingWork from '@/components/artical_manage/ExaminingWork'

import ExaminedArtical from '@/components/examin_manage/ExaminedArtical'
import ExaminedComment from '@/components/examin_manage/ExaminedComment'
import ExaminingArtical from '@/components/examin_manage/ExaminingArtical'
import ExaminingComment from '@/components/examin_manage/ExaminingComment'

import PersonalCenter from '@/components/system_manage/PersonalCenter'
import PermissionManage from '@/components/system_manage/PermissionManage'


import ElemenUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import { store } from '../store/store';

Vue.use(Router)
Vue.use(ElemenUI)
const vueRouter =  new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login,
    },
    {
      path: '/register',
      name: 'Register',
      component: Register
    },
    {
      path: '/index',
      name: 'Index',
      component: Index,
      meta:{
        requireAuth:true
      },
      children:[
        {
          path:'',
          name:'ExistChannel',
          meta:{
            requireAuth:true
          },
          component:ExistChannel
        },
        {
          path:'/create_channel',
          name:'CreateChannel',
          meta:{
            requireAuth:true
          },
          component:CreateChannel
        },
        {
          path:'/completed_work',
          name:'CompletedWork',
          meta:{
            requireAuth:true
          },
          component:CompletedWork
        },
        {
          path:'/create_work',
          name:'CreateWork',
          meta:{
            requireAuth:true
          },
          component:CreateWork
        },
        {
          path:'/examining_work',
          name:'ExaminingWork',
          meta:{
            requireAuth:true
          },
          component:ExaminingWork
        }
      ]
    },
    {
      path: '/examin_manage',
      name: 'examin_manage',
      component: Index,
      meta:{
        requireAuth:true
      },
      children:[
        {
          path:'/examining_artical',
          name:'ExaminingArtical',
          meta:{
            requireAuth:true
          },
          component:ExaminingArtical
        },
        {
          path:'/examining_comment',
          name:'ExaminingComment',
          meta:{
            requireAuth:true
          },
          component:ExaminingComment
        },
        {
          path:'/examined_artical',
          name:'ExaminedArtical',
          meta:{
            requireAuth:true
          },
          component:ExaminedArtical
        },
        {
          path:'/examined_comment',
          name:'ExaminedComment',
          meta:{
            requireAuth:true
          },
          component:ExaminedComment
        }
      ]
    },
    {
      path: '/artical_manage',
      name: 'artical_manage',
      component: Index,
      meta:{
        requireAuth:true
      },
      children:[
        {
          path:'/completed_work',
          name:'CompletedWork',
          meta:{
            requireAuth:true
          },
          component:CompletedWork
        },
        {
          path:'/create_work',
          name:'CreateWork',
          meta:{
            requireAuth:true
          },
          component:CreateWork
        },
        {
          path:'/examining_work',
          name:'ExaminingWork',
          meta:{
            requireAuth:true
          },
          component:ExaminingWork
        }
      ]
    },
    {
      path:'/system_manage',
      name:'SystemManage',
      component:Index,
      meta:{
        requireAuth:true
      },
      children:[
        {
          path:'/personal_center',
          name:'PersonalCenter',
          meta:{
            requireAuth:true
          },
          component:PersonalCenter
        },
        {
          path:'/permission_manage',
          name:'PermissionManage',
          meta:{
            requireAuth:true
          },
          component:PermissionManage
        }
      ]
    }
  ]
})
//路由拦截
vueRouter.beforeEach((to,from,next)=>{
  if(to.meta.requireAuth){
    if(sessionStorage.getItem("token")){
      next();
    }else
      next(
        {
          path:'/',      
        }
      )
  }else
    next();
})
export default vueRouter
